package com.dev.sacot41.scviewpager;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;

/**
 * Created by Samuel on 2015-07-06.
 */
public class SCSizeAnimation extends SCPageAnimation {

    /**
     * height variation, in percentage
     */
    public float dHeigh;

    /**
     * width variation, in percentage
     */
    public float dWidth;

    private int startHeigh;
    private int startWidth;

    /**
     * @param forPage page to apply animation
     * @param dh      height variation, in percentage
     * @param dw      width variation, in percentage
     */
    public SCSizeAnimation(int forPage, float dh, float dw) {
        this.page = forPage;
        this.dHeigh = dh;
        this.dWidth = dw;
    }

    @Override
    public void applyTransformation(Component onView, float positionOffset) {
        ComponentContainer.LayoutConfig param = onView.getLayoutConfig();
        if (positionOffset <= 0) {
            startHeigh = onView.getHeight();
            startWidth = onView.getWidth();
            return;
        }
        param.height = (int) (dHeigh * startHeigh * positionOffset) + startHeigh;
        param.width = (int) (dWidth * startHeigh * positionOffset) + startWidth;
        onView.setLayoutConfig(param);
    }

}
